﻿@model CustomerAddressListModel

@using SmartStore.Web.Models.Customer;
@using SmartStore.Services.Directory;

@{
	Html.AddTitleParts(T("PageTitle.Account").Text);

	Layout = "_MyAccount";
	ViewBag.PageClassToken = "addresses";
	ViewBag.PageTitle = T("Account.CustomerAddresses").Text;
}

@if (Model.Addresses.Count == 0)
{
	<div class="alert alert-warning">@T("Account.CustomerAddresses.NoAddresses")</div>
}

<div class="add-address">
	<a class="btn btn-primary btn-lg add-address-button mb-4" href="@Url.Action("AddressAdd")" rel="nofollow">
		<i class="fa fa-plus"></i>
		<span>@T("Common.AddNew")</span>
	</a>
</div>

@if (Model.Addresses.Count == 0)
{
	return;
}

<div class="card-deck card-cols-sm-1 card-cols-lg-2 address-list">
    @for (int i = 0; i < Model.Addresses.Count; i++)
    {
        var address = Model.Addresses[i];
                    
        <div class="card shadow-sm address-list-item">
            <div class="card-body">
				<h4 class="card-title">@address.GetFormattedName()</h4>

				<div class="mb-2">
					<div class="email">
						@Html.LabelFor(model => model.Addresses[i].Email, new { @class = "m-0" }):
						@address.Email
					</div>
					@if (address.PhoneEnabled)
					{
						<div class="phone">
							@Html.LabelFor(model => model.Addresses[i].PhoneNumber, new { @class = "m-0" }):
							@address.PhoneNumber
						</div>
					}
					@if (address.FaxEnabled && address.FaxNumber.HasValue())
					{
						<div class="fax">
							@Html.LabelFor(model => model.Addresses[i].FaxNumber, new { @class = "m-0" }):
							@address.FaxNumber
						</div>
					}
				</div>

				<div>
					@Html.Raw(address.FormattedAddress)
				</div>
            </div>
                
			<div class="card-footer d-flex p-0">
                <a class="btn btn-secondary btn-lg btn-flat rounded-0 edit-address-button" href="@Url.Action("AddressEdit", new { id = address.Id })">
					<span>@T("Common.Edit")</span>
				</a>
                <a class="btn btn-danger btn-lg btn-flat rounded-0 delete-address-button" href="@Url.Action("AddressDelete", new { id = address.Id })" onclick='return confirm(@T("Common.AreYouSure").JsText);'>
					<span>@T("Common.Delete")</span>
				</a>
            </div>
        </div>
    }
</div>
